import type { NextRequest } from 'next/server';
import { spritClient } from "@/grpc";
import { project_sprit_api } from "@/proto_gen_ts/proto/project_sprit_api";

export async function GET(request: NextRequest): Promise<Response> {
    const params = request.nextUrl.searchParams;
    const id = params.get("id") ?? "";
    const secret = params.get("secret") ?? "";

    return new Promise((resolve, reject) => {
        spritClient.listSummaryItemByShare(new project_sprit_api.ListSummaryItemByShareRequest({ shareId: id, shareSecret: secret }), (error, response) => {
            if (error) {
                reject(error);
            } else {
                resolve(Response.json(response?.toObject()));
            }
        });
    });
}